<?php
// @formatter:off
/**
 * @file s.images.php
 * @author Alejandro Dario Simi
 * @date $Date: 2014-05-04 01:33:52 +0000 (Sun, 04 May 2014) $
 *
 * $Id: s.images.php 111 2014-05-04 01:33:52Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/services/images/s.images.php $
 */
// @formatter:on

$wcServiceStatus = false;
$wcServiceErrorCode = 500;

if(defined("__SERVICE__")) {
	if($_SERVER["REQUEST_METHOD"] == "POST") {
		if($wcImage && $wcImage->ok()) {
			if(isset($_POST["NEXT_NAME"]) && $wcProfile->allowedTo(WC_PERM_IMAGE_RENAME)) {
				$next = trim($_POST["NEXT_NAME"]);
				$name = explode(".", $wcImage->next_name ? $wcImage->next_name : $wcImage->name);
				$ext = array_pop($name);
				$name = implode(".", $name);

				if(!$next) {
					$wcServiceErrorMsg = "No new name specified";
				} elseif($next == $name) {
					$wcServiceErrorMsg = "New name is the same than current one";
				} else {
					$wcServiceStatus = true;
					$wcImage->next_name = "{$next}.{$ext}";
				}
			} elseif(!$wcProfile->allowedTo(WC_PERM_IMAGE_RENAME)) {
				$wcServiceErrorCode = 403;
				$wcServiceErrorMsg = "Unable to access service";
			} else {
				$wcServiceErrorMsg = "This service was call with invalid parameters";
			}
		} else {
			$wcServiceErrorMsg = "This service was call with invalid parameters";
		}
	} else {
		$wcServiceErrorCode = 403;
		$wcServiceErrorMsg = "This service only works on POST method";
	}
} else {
	$wcServiceErrorCode = 403;
	$wcServiceErrorMsg = "Unable to access service";
}
?>